package cn.flying.cloud.flow.core.listener.event.callback;

import org.flowable.common.engine.api.delegate.event.FlowableEvent;
import org.flowable.engine.delegate.event.impl.FlowableEntityEventImpl;
import org.flowable.task.service.impl.persistence.entity.TaskEntityImpl;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

/**
 * 任务完成监听
 *
 * @author: admin
 * @date: 2023年02月26日 08:25
 * @version: 1.0
 */
@Component
public class TaskCompletedListenerCallback implements EventListenerCallback {
    private final Logger logger = LoggerFactory.getLogger(this.getClass());

    @Override
    public void execute(FlowableEvent event) {
        logger.info("==========任务完成监听器回调处理---start===========");
        System.out.println("事件类型：" + event.getType().name());
        FlowableEntityEventImpl entityEvent = (FlowableEntityEventImpl) event;
        TaskEntityImpl entity = (TaskEntityImpl) entityEvent.getEntity();
        System.out.println(entityEvent.getExecutionId());
        System.out.println("实体：" + entityEvent);

        logger.info("流程【{}】处理完成，实例ID：【{}】，任务：【{}-{}】完成，", entity.getProcessDefinitionId(), entity.getProcessInstanceId(), entity.getId(), entity.getTaskDefinitionKey());
        logger.info("==========任务创建监听器回调处理---end===========");
    }
}
